﻿using System;
using System.Collections.Generic;
using UvsChess;
using StudentAI;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ChessUnitTest
{
    [TestClass]
    public class TestMoveGeneration
    {
        #region PawnGeneration
        [TestMethod]
        public void TestAllMoveGenerationAtStart()
        {
            //This will ensure only the pawn and the knight move initially
            string StartingBoardState = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR";
            //01234567
            //rnbqkbnr/0
            //pppppppp/1
            //________/2
            //________/3
            //________/4
            //________/5
            //PPPPPPPP/6
            //RNBQKBNR/7
            //Moves that should be in the set
            //n(1,0)->((0,2)|(2,2)), (6,0)->((5,2)|(7,2))
            //p(_,1)->(_,2)|(_,3)
            //P(_,6)->(_,5)|(_,4)
            //N(1,7)->((0,5)|(2,5)), (6,7)->((5,5)|(7,5))
            List<ChessMove> blackMoves = MoveGeneration.getAllMoves(new ChessBoard(StartingBoardState), ChessColor.Black);
            List<ChessMove> whiteMoves = MoveGeneration.getAllMoves(new ChessBoard(StartingBoardState), ChessColor.White);
            Assert.IsTrue(blackMoves.Contains(new ChessMove(new ChessLocation(1, 0), new ChessLocation(0, 2))));
            Assert.IsTrue(blackMoves.Contains(new ChessMove(new ChessLocation(1, 0), new ChessLocation(2, 2))));
            Assert.IsTrue(blackMoves.Contains(new ChessMove(new ChessLocation(6, 0), new ChessLocation(5, 2))));
            Assert.IsTrue(blackMoves.Contains(new ChessMove(new ChessLocation(6, 0), new ChessLocation(7, 2))));
            for (int x = 0; x < ChessBoard.NumberOfColumns; x++) {
                Assert.IsTrue(blackMoves.Contains(new ChessMove(new ChessLocation(x, 1), new ChessLocation(x, 2))));
                Assert.IsTrue(blackMoves.Contains(new ChessMove(new ChessLocation(x, 1), new ChessLocation(x, 3))));
            }

            Assert.IsTrue(whiteMoves.Contains(new ChessMove(new ChessLocation(1, 7), new ChessLocation(0, 5))));
            Assert.IsTrue(whiteMoves.Contains(new ChessMove(new ChessLocation(1, 7), new ChessLocation(2, 5))));
            Assert.IsTrue(whiteMoves.Contains(new ChessMove(new ChessLocation(6, 7), new ChessLocation(5, 5))));
            Assert.IsTrue(whiteMoves.Contains(new ChessMove(new ChessLocation(6, 7), new ChessLocation(7, 5))));
            for (int x = 0; x < ChessBoard.NumberOfColumns; x++)
            {
                Assert.IsTrue(whiteMoves.Contains(new ChessMove(new ChessLocation(x, 6), new ChessLocation(x, 5))));
                Assert.IsTrue(whiteMoves.Contains(new ChessMove(new ChessLocation(x, 6), new ChessLocation(x, 4))));
            }
        }
        #endregion
    }
}
